package com.briup.mt.service.impl;

import com.briup.mt.bean.BasePrivilege;
import com.briup.mt.bean.BasePrivilegeExample;
import com.briup.mt.dao.BasePrivilegeMapper;
import com.briup.mt.service.IBasePrivilegeService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

@Service
public class BasePrivilegeServiceImpl implements IBasePrivilegeService {
    @Resource
    private BasePrivilegeMapper basePrivilegeMapper;
    @Override
    public List<BasePrivilege> query(String name) {
        BasePrivilegeExample example =new BasePrivilegeExample();
        if(!StringUtils.isEmpty(name)){
            example.createCriteria().andNameLike("%"+name+"%");
        }
        List<BasePrivilege> list=basePrivilegeMapper.selectByExample(example);
        return list;
    }

    @Override
    public List<BasePrivilege> routefind(String route) {
        BasePrivilegeExample example =new BasePrivilegeExample();
        if(!StringUtils.isEmpty(route)){
            example.createCriteria().andRouteLike("%"+route+"%");
        }
        List<BasePrivilege> list=basePrivilegeMapper.selectByExample(example);
        return list;
    }

    @Override
    public void saveOrUpdate(BasePrivilege basePrivilege) {
        if(basePrivilege.getId()==null){

            basePrivilegeMapper.insert(basePrivilege);
        }else{
            basePrivilegeMapper.updateByPrimaryKey(basePrivilege);
        }
    }

    @Override
    public void deleteById(long id) {
       basePrivilegeMapper.deleteByPrimaryKey(id);
    }
}
